package com.example.contrpller;

import com.example.entiy.Book;
import com.example.service.BookService;
import org.apache.juli.logging.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping
@Controller
public class BookController {
    @Autowired
    private BookService bookService;
    @GetMapping("/book")
    public ResponseEntity<Book> getBookById(@RequestParam Integer id) {
        Book book = bookService.getById(id);

        if (book != null) {
            // 返回成功（HTTP 200 OK），并将查询到的书籍对象作为JSON响应体
            return ResponseEntity.ok(book);
        } else {
            // 如果未找到书籍，返回HTTP 404 Not Found
            return ResponseEntity.notFound().build();
        }
    }
}
